// Author: Domien Nowicki

#include "Pixel.h"

Pixel::Pixel(unsigned long newrgb): rgb(newrgb)
{
}

Pixel::Pixel(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha)
{
	SetAlpha(alpha);
	SetBlue(blue);
	SetRed(red);
	SetGreen(green);
}

Pixel::Pixel(const Pixel& rhs): rgb(rhs.rgb)
{
}

Pixel::~Pixel()
{
}

Pixel& Pixel::operator=(const Pixel& rhs)
{
	rgb = rhs.rgb;
	return *this;
}

void Pixel::SetRgb(unsigned long newrgb)
{
	rgb = 0xFFFFFF & newrgb;
}

void Pixel::SetBlue(unsigned int blue)
{
	rgb = (rgb & 0xFFFFFF00) | (0x0000FF & (blue<<0));
}

void Pixel::SetGreen(unsigned int green)
{
	rgb = (rgb & 0xFFFF00FF) | (0x00FF00 & (green<<8));
}

void Pixel::SetRed(unsigned int red)
{
	rgb = (rgb & 0xFF00FFFF) | (0xFF0000 & (red<<16));
}

void Pixel::SetAlpha(unsigned int alpha)
{
	rgb = (rgb & 0x00FFFFFF) | (0xFF000000 & (alpha<<24));
}

void Pixel::SetOpaque()
{
	SetAlpha(255);
}

unsigned long Pixel::GetRgb() const
{
	return rgb;
}

unsigned int Pixel::GetBlue() const
{
	return (rgb>>0) & 0xFF;
}

unsigned int Pixel::GetGreen() const
{
	return (rgb>>8) & 0xFF;
}

unsigned int Pixel::GetRed() const
{
	return (rgb>>16) & 0xFF;
}

unsigned int Pixel::GetAlpha() const
{
	return (rgb>>24) & 0xFF;
}

bool Pixel::IsTransparent() const
{
	return GetAlpha() != 255;
}

void Pixel::SetTransparent()
{
	SetAlpha(0);
}

bool Pixel::operator==(const Pixel& rhs)
{
	return rgb == rhs.rgb;
}

bool Pixel::operator!=(const Pixel& rhs)
{
	return rgb != rhs.rgb;
}
